package com.huizhonglm.diap.core.utils;

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.Window;
import android.view.WindowManager;

import com.huizhonglm.diap.R;

public class ProUtil {
    /**
     * 单例
     */
    private static ProUtil mInstance = null;
    /**
     * 加载进度条 *
     */
    private Dialog mDialog;

    /**
     * 获取单例
     *
     * @return ProgressUtil对象
     */
    public static ProUtil onCreate() {
        if (mInstance == null) {
            synchronized (ProUtil.class) {
                if (mInstance == null) {
                    mInstance = new ProUtil();
                }
            }
        }
        return mInstance;
    }

    private ProUtil() {
    }

    /**
     * 显示进度条
     *
     * @param con       上下文
     */
    public void show(Context con) {
        if (null == con) {
            return;
        }
        mDialog = null;
        mDialog = new Dialog(con);
        mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        mDialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        mDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
        mDialog.setCancelable(false);
        mDialog.setCanceledOnTouchOutside(false);
        mDialog.show();
        Window window = mDialog.getWindow();
        window.setContentView(R.layout.dialog_progress);
    }

    /**
     * 隐藏进度条
     */
    public void hide() {
        if (mDialog != null && mDialog.isShowing()) {
            mDialog.cancel();
        }
    }
}
